package admin

import (
	"context"

	"server/internal/svc"
	"server/internal/types"
	"server/models"
	"server/utils"

	"github.com/zeromicro/go-zero/core/logx"
)

type SpecValueInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSpecValueInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SpecValueInfoLogic {
	return &SpecValueInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SpecValueInfoLogic) SpecValueInfo(req *types.IdForm) (resp *types.SpecValueResp, err error) {
	tx := utils.Db.Model(&models.SpecValue{}).Joins("LEFT JOIN spec_template ON spec_values.spec_template_id = spec_template.id").Joins("LEFT JOIN spec_keys ON spec_values.spec_key_id = spec_keys.id").Where("spec_values.id = ?", req.Id).Select("spec_values.*, spec_template.name as spec_template_name, spec_keys.name as spec_key_name")

	resp = &types.SpecValueResp{}
	err = utils.TxData(tx, resp)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
